<template>

	<view class="search">
		<!-- <u-navbar title="搜索" @rightClick="rightClick" :autoBack="true" :bgColor="bgColor" :titleStyle="titleStyle"
			leftIconColor="#ffffff">
		</u-navbar> -->

		<!-- <view class="" :style="{'height':globalData.navHeight-20 +'px'}"></view> -->

		<view class="searchBox">
			<view class="inputBox">
				<image class="searchIcon" src="http://120.76.245.175/uploads/image/searchIcon.png"
					style="width: 26rpx; height: 26rpx;">
					<input class="inputitem" type="text" v-model="searchVal" placeholder="请输入" @confirm="handleSearch"
						@input="handleInput">
					<image class="searchIcon" src="http://120.76.245.175/uploads/image/searchIcon.png"
						style="width: 26rpx; height: 26rpx;">
						<div class="searchBtn" @click="handleSearch">
							搜索
						</div>
						<image v-if="searchVal" class="delIcon" src="http://120.76.245.175/uploads/image/delicon.png"
							style="width: 36rpx; height: 36rpx;z-index: 999;" @click="handledelValue">
			</view>
		</view>

		<view class="" style="height:92rpx ;"></view>

		<view class="DataListBox">
			<view class="dataItem" v-for="(item,index) in dataList" :key="index" @click="handleDetail(item.id)">

				<view class="dataItemLft">
					<image class="refreshimg" :src="item.image" mode="aspectFill"
						style="width: 290rpx; height: 240rpx;border-radius: 20rpx;">
					</image>
				</view>
				<view class="dataItemRight">
					<view class="name">
						{{item.name}}
					</view>
					<!-- 	<view class="distanceBox">
						<view v-if="item.metro" class="distance">
							<text v-if="item.metro"></text>{{item.metro == null ? "" : item.metro}}
						</view>
						<view class="km" style="color:#F8AD22 ;margin-top: 40rpx;">
							{{item.remark==null ? '' : item.remark}}{{item.distance}}km
						</view>
					</view> -->
					<view class="distanceBox">
						<view class="distance">
							<view class="">
								<text v-if="item.metro1">距</text>{{item.metro1 == null ? "" : item.metro1}}
							</view>
							<view v-if="item.remark" class="">
								{{item.metro == null ? "" : item.metro}}{{item.remark==null ? '' : item.remark}}米
							</view>
						</view>
						<view class="km" style="color:#F8AD22 ;margin-top: 40rpx;text-align: right;">
							{{item.distance}}km
						</view>
					</view>
					<scroll-view class="advantage" scroll-x="true">
						<view class="advantageitem" v-for="(subitem,index) in item.advantage" :key="item.id">
							{{subitem.name}}
						</view>
					</scroll-view>
					<view class="expense">
						<view v-if="item.price !='0.00'" class="expenseitem">
							{{item.price}}元/月
						</view>
						<view v-else class="expenseitem">
							致电询价
						</view>
						<view class="collect">
							{{item.collect}}收藏
						</view>

					</view>

				</view>
			</view>
		</view>

		<view class="" style="height: 50rpx;">

		</view>





	</view>

</template>

<script>
	import {
		houseList
	} from "@/api/api.js"
	export default {
		data() {
			return {
				globalData: {
					statusBarHeight: 0, // 状态导航栏高度
					navHeight: 0, // 总体高度
					navigationBarHeight: 0, // 导航栏高度(标题栏高度)
				},
				bgColor: "#F8AD22",
				titleStyle: {
					color: "#ffffff",
					fontSize: "32rpx",
					fontFamily: "PingFang SC-Bold, PingFang SC",
					fontweight: "bold",
				},
				searchVal: "",
				pageNum: 1,
				dataList: [],
			}
		},
		onLoad() {
			this.getNavbarHeight()
		},
		onReachBottom() {
			this.pageNum++;
			this.handleLoad();
		},
		methods: {
			handleInput() {
				if (this.inputValue === '') {
					// 输入框被清空，此时可以获取时间戳
					this.pageNum = 1
					this.dataList = []
				}
			},
			async handleSearch() {
				console.log("333333333333333")
				this.dataList = []
				if (this.searchVal == "") {
					uni.showToast({
						title: '请输入搜索内容！!',
						icon: "none",
						duration: 1000
					});
					return
				}
				this.handleLoad()

				console.log("搜索房子", res)
			},
			async handleLoad() {
				let res = await houseList({
					position: "2",
					name: this.searchVal,
					page_size: 5,
					page: this.pageNum
				})
				if (res.code == 1000) {
					// this.dataList = res.data.data
					res.data.data.forEach((item, index) => {
						this.dataList.push(item)
					})
				} else {
					uni.showToast({
						title: '暂无此房源!',
						icon: "none",
						duration: 1000
					});
				}
			},
			handleDetail(id) {

				uni.navigateTo({
					// url: "./homedetail"
					url: `./homedetail?id=${id}`
				})
			},
			getNavbarHeight() {
				// 状态栏高度
				this.globalData.statusBarHeight = uni.getSystemInfoSync().statusBarHeight

				// #ifdef MP-WEIXIN
				// 获取微信胶囊的位置信息 width,height,top,right,left,bottom
				const custom = wx.getMenuButtonBoundingClientRect()
				// console.log(custom)

				// 导航栏高度(标题栏高度) = 胶囊高度 + (顶部距离 - 状态栏高度) * 2
				this.globalData.navigationBarHeight = custom.height + (custom.top - this.globalData.statusBarHeight) * 2
				// console.log("导航栏高度："+this.globalData.navigationBarHeight)

				// 总体高度 = 状态栏高度 + 导航栏高度
				this.globalData.navHeight = this.globalData.navigationBarHeight + this.globalData.statusBarHeight

				// #endif

				console.log("高度", this.globalData)

			},

			handledelValue() {
				this.searchVal = ""
				this.dataList = []
			},
		},
	}
</script>

<style scoped lang="scss">
	.search {

		.searchBox {
			width: 100%;
			padding: 10rpx 30rpx;
			background-color: #F8AD22;
			position: fixed;

			.inputBox {
				position: relative;
				background-color: #ffffff;
				width: 690rpx;
				border-radius: 10rpx;

				.searchIcon {
					position: absolute;
					top: 23rpx;
					left: 30rpx;
				}

				.delIcon {
					position: absolute;
					top: 20rpx;
					right: 135rpx;
				}

				.inputitem {
					width: 535rpx;
					height: 72rpx;
					background: #FFFFFF;
					border-radius: 12rpx 12rpx 12rpx 12rpx;
					opacity: 1;
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
					line-height: 39rpx;
					padding-left: 66rpx;
					box-sizing: border-box;
				}

				.searchBtn {
					width: 118rpx;
					height: 64rpx;
					background: #F8AD22;
					border-radius: 12rpx 12rpx 12rpx 12rpx;
					opacity: 1;
					color: #ffffff;
					text-align: center;
					line-height: 64rpx;
					font-size: 28rpx;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: bold;
					position: absolute;
					top: 5rpx;
					right: 5rpx;
					z-index: 999;
				}
			}

		}


		.DataListBox {
			width: 690rpx;
			margin: 0 auto;
			margin-top: 10px;

			.dataItem {
				display: flex;
				width: 690rpx;
				padding: 10rpx;
				box-sizing: border-box;
				background-color: #ffffff;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				margin-bottom: 20rpx;

				.dataItemLft {
					margin-right: 20rpx;
				}

				.dataItemRight {
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					width: 390rpx;

					.name {
						font-size: 28rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #333333;
						line-height: 33rpx;

					}

					.distanceBox {
						font-size: 22rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
						line-height: 26rpx;
						display: flex;
						justify-content: space-between;

						.distance {
							width: 260rpx;
						}

					}

					.advantage {
						white-space: nowrap;
						width: 100%;

						.advantageitem {
							padding: 5rpx 15rpx;
							height: 40rpx;
							background: #FFF5E1;
							border-radius: 8rpx 8rpx 8rpx 8rpx;
							font-size: 20rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #F06703;
							line-height: 40rpx;
							text-align: center;
							margin-right: 10rpx;
							display: inline-block;
						}
					}

					.expense {
						display: flex;
						justify-content: space-between;

						.expenseitem {
							font-size: 30rpx;
							font-family: PingFang SC-Bold, PingFang SC;
							font-weight: bold;
							color: #F23A00;
							line-height: 35rpx;
						}

						.collect {
							font-size: 22rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #F8AD22;
							line-height: 26rpx;
						}
					}
				}
			}

		}
	}
</style>